/**
 * @Author: wyt
 * @Description: 用户是否登陆状态管理
 */
import { ref } from "vue";
import { defineStore } from "pinia";

export const useUserStore = defineStore(
  "user",
  () => {
    const currentUser = ref(
      JSON.parse(localStorage.getItem("currentUser")) || null
    );
    const setCurrentUser = (newUser) => {
      currentUser.value = newUser;
      localStorage.setItem("currentUser", JSON.stringify(newUser));
    };

    return { currentUser, setCurrentUser };
  },
  {
    persist: true,
  }
);
